/**************************************************************************************************

	NSurvey - The web survey and form engine
	Copyright (c) 2004, Thomas Zumbrunn. (http://www.nsurvey.org)

	Dotnetnuke PA module 
	Copyright (c) 2004, Oliver Hine (oliver.hine@gmail.com)

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.


************************************************************************************************/
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Votations.NSurvey.Resources;
using Votations.NSurvey.WebControls.UI;
using Votations.NSurvey.WebAdmin.UserControls;

namespace Votations.NSurvey.WebAdmin
{
	public class MailingPollStatus : Page
	{
		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		protected ResultsBar ProgressBar;
		System.Resources.ResourceManager _resourceManagerInstance = 
			new System.Resources.ResourceManager("Votations.NSurvey.WebAdmin.Resources.NSurveyAdmin",
			System.Reflection.Assembly.GetExecutingAssembly());

		private void Page_Load(object sender, System.EventArgs e)
		{
			// Check if the task has been finished
			object obj = SyncDataStore.GetRecords(Session.SessionID);
			if(obj!=null)
			{ 
				Response.Write("<center>"+_resourceManagerInstance.GetString("AllInvitationSendMessage")+"</center>");
				ProgressBar.Visible = false;
				SyncDataStore.Remove(Session.SessionID);
				SyncDataStore.Remove(Session.SessionID + ":" + "Progress");
			}
			else
			{
				object error = SyncDataStore.GetRecords(Session.SessionID + ":" + "Error");
				if(error != null)
				{
					throw (Exception)error;
				}
				else
				{
					// Retrieve the current progress of the task
					object mailingProgress = SyncDataStore.GetRecords(Session.SessionID + ":" + "Progress");
					if(mailingProgress != null)
					{
						ProgressBar.Progress = int.Parse(mailingProgress.ToString());
					}
					else
					{
						ProgressBar.Progress = 0;
					}
					ProgressBar.TableWidth = Unit.Pixel(400);
					Response.AddHeader("Refresh","2");
				}
			}
		}

	}
}
